Idle Method Example

This example uses the Idle method to ensure that an output procedure is accessing the most current data available from the database. The IdleOutput procedure is required for this procedure to run.

Sub IdleX()

   Dim dbsNorthwind As Database
   Dim strCountry As String
   Dim strSQL As String
   Dim rstOrders As Recordset

   Set dbsNorthwind = OpenDatabase("Northwind.mdb")

   ' Get name of country from user and build SQL statement 
   ' with it.
   strCountry = Trim(InputBox("Enter country:"))
   strSQL = "SELECT * FROM Orders WHERE ShipCountry = '" & _
      strCountry & "' ORDER BY OrderID"

   ' Open Recordset object with SQL statement.
   Set rstOrders = dbsNorthwind.OpenRecordset(strSQL)

   ' Display contents of Recordset object.
   IdleOutput rstOrders, strCountry

   rstOrders.Close
   dbsNorthwind.Close

End Sub

Sub IdleOutput(rstTemp As Recordset, strTemp As String)

   ' Call the Idle method to release unneeded locks, force 
   ' pending writes, and refresh the memory with the current 
   ' data in the .mdb file.
   DBEngine.Idle dbRefreshCache

   ' Enumerate the Recordset object.
   With rstTemp
      Debug.Print "Orders from " & strTemp & ":"
      Debug.Print , "OrderID", "CustomerID", "OrderDate"
      Do While Not .EOF
         Debug.Print , !OrderID, !CustomerID, !OrderDate
         .MoveNext
      Loop
   End With

End Sub